package com.guigu.utils;

import lombok.Data;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.util.Date;

@Data
public class DateConverter implements Converter<String, Date> {

    private String[] patterns;

    @Override
    public Date convert(String source) {
        try {
            Date date = DateUtils.parseDate(source, patterns);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
}
